<template>
    <div class="add-summary w-100 h-100">
        <el-card class="box-card-table h-100" shadow="never">
            <div slot="header" class="clearfix">
                <span class="fl">添加总结</span>
                <el-button class="fr" @click="goback" style="padding:6px;">返回</el-button>
            </div>
            <div class="h-100">
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="总结名称：" prop="bW_Name">
                        <el-input v-model="ruleForm.bW_Name" placeholder="总结名称"></el-input>
                    </el-form-item>
                    <el-form-item label="详细内容：" prop="bW_Content">
                        <!-- <quill-editor v-model="ruleForm.bW_Content"
                            style="line-height:0px;"
                            ref="myQuillEditor"
                            :options="editorOption">
                        </quill-editor> -->
                        <ele-editor editorId=“summaryEditor” v-model="ruleForm.bW_Content"></ele-editor>
                    </el-form-item>
                    <el-form-item class="t-r" style="margin-top:10px;">
                        <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </el-card>
    </div>
</template>

<script>
import elewarp from '@/components/warp-slot.vue'
// 添加学生
import {addworklist,getworkinfo,editworkinfo} from '@/api/index.js'
import eleEditor from '@/components/editor.vue'
export default {
    name: 'addsummary',
    components: {
        elewarp,
        eleEditor
    },
    data() {
        return {
            ruleForm:{
                bW_Name:'',
                bW_Content:'',
                bTPID:''
            },
            editorOption:{
                modules:{
                    toolbar:[
                        ["bold", "italic", "underline", "strike"],
                        ["code-block",{list: "ordered"},{list: "bullet"}],
                        [{"color":[]},{"background":[]}],
                        [{indent: "-1"},{indent: "+1"}],
                        [{align: []}],
                        ["link", "image"]
                    ]
                },
                placeholder:'请输入'
            },
            rules:{
                bW_Name:[
                    { required: true, message: '名称不能为空', trigger: 'blur' },
                    {min:3,max:30,message:'长度再3-30个字符之间',trigger: 'blur'}
                ],
                bW_Content:[
                    { required: true, message: '内容不能为空', trigger: 'blur' }
                ],
            },
            week:[]
        }
    },
    computed:{
        rowvalue(){
            return this.week.length + 2
        }
    },
    created(){
        this.workid = this.$route.query.id;
        if(this.workid) {
            this._getworkInfo();
        }
    },
    methods:{
        submitForm(){
            this.$refs.ruleForm.validate((valid) => {
                if (valid) {
                    let params ={
                        ...this.ruleForm
                    }
                    if(this.workid) {
                        editworkinfo({...params,bWID:this.workid}).then((res) => {
                            if(res) {
                                if(res.code == 200) {
                                    this.$util.tipsMsg('success','修改成功！');
                                    this.goback()
                                } else {
                                    this.$util.tipsMsg('error',res.message);
                                }
                            }
                        }).catch((err) => {

                        })
                    } else {
                        addworklist({...this.ruleForm}).then((res) => {
                            if(res) {
                                if(res.code == 200) {
                                    this.$util.tipsMsg('success','添加成功！');
                                    this.goback()
                                } else {
                                    this.$util.tipsMsg('error',res.message);
                                }
                            }
                        }).catch(err => {
                            
                        })
                    }
                } else {
                    return false;
                }
            })
            
        },
        _getworkInfo(){
            getworkinfo({bWID:this.workid}).then((res) => {
                if(res) {
                    console.log(res)
                    for (const key in this.ruleForm) {
                        if (this.ruleForm.hasOwnProperty(key)) {
                            let _key = key.substr(1);
                            if( _key in res) {
                                this.ruleForm[key] = res[_key];
                            }
                        }
                    }
                }
            })
        },
        onReset(){
            this.$refs.searchform.resetFields()
        },
        // 全选
        goback(){
            this.$router.push({path:'/summary'})
        },
    }
}
</script>
<style lang="less">
.add-summary{
    box-sizing: border-box;
    .line-height{
        line-height: 20px;
    }
    .ql-container.ql-snow{
        min-height: 300px;
    }
    .el-card{
        box-sizing: border-box;
    }
    .el-card__body{
        height:calc(100% - 70px);
        box-sizing: border-box;
    }
    .box-card-table{
        overflow-y: auto;
        box-sizing: border-box;
    }
}
</style>
